{if isset($fields) && !empty($fields)}{strip}



{assets css="form-customizing"}
{if !$options.mode.readonly}
	{*{assets js="form::iMask form::ajax form::tidy ui::helper-html"}*}
	{assets js="formx::iMask formx::ajax"}
{/if}
{if $options.file}
	{js include="form::aim"}
{/if}

{assign var=fid value=$options.name|default:0}

<form action="{capture assign=act}{$options.action|default:'./'}{/capture}{if $options.mode.noajax}{$act|replace:'/ajax/':'/'}{else}{$act}{/if}" method="{$options.method|default:'POST'|strtolower}" id="{$fid}" {if !$options.mode.noajax && isset($options.target)}target="{$options.target}"{/if} class="simple {capture assign=cls}{$options.class|default:'ajax'}{/capture}{if !$options.mode.noajax}{$cls}{else}{$cls|replace:'ajax':''}{/if}" enctype="{$options.enctype|default:'application/x-www-form-urlencoded'}" {if !$options.mode.noajax && $options.file}onsubmit="javascript:return AIM.submit(this, {ldelim}'onStart':window.startCallback,'onComplete':window.completeCallback{rdelim});"{/if}>


{if $options.file}<input type="hidden" name="file" value="upload" />{/if}

{assign var=hiddenfields value=""}

{foreach from=$fields key=k item=i}

	{assign var=kid value=$k|replace:'[':''|replace:']':''}

	{if isset($i.type) && $i.type=='hidden'}
		{capture assign=hiddenfields}{$hiddenfields}<input name="{$k}" type="hidden" value="{$i.value.0|escape}" />{/capture}

	{elseif isset($i.type)}

		{if $i.type=='header'}
			{if isset($i.label)}
				<div class="form-header {$i.class|default:''}"><h2>{$i.label|default:$k}</h2></div>
			{/if}

		{else}
			<div id="form{$fid}_{$kid}_container" class="form-field {$i.type} {$i.class} clearfix">
				{if $i.type=='check'}<label class="empty">&nbsp;</label>{else}<label for="form{$fid}_{$kid}">{$i.label|default:$k} {if @$i.required}<a style="color:red" title="required">*</a>{/if}</label>{/if}

{assign var=oi value=$i}
{php}$this->_tpl_vars['oiv'] = (array)(_::pick(@$this->_tpl_vars['i']['value'],''));{/php}

{foreach from=$oiv item=i_value}

				{if $i.type=='static'}
					<span id="form{$fid}_{$kid}" class="{$i.class|default:''} textbox">{$i_value} &nbsp;</span>

				{elseif $i.type=='text'}
					<textarea id="form{$fid}_{$kid}" name="{$k}" class="field-type-{$i.type} textarea {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if}>{$i_value|default:''|escape}</textarea>
					{if $options.html || $i.html}<a class="js-button js-html-helper">Show HTML Cheatsheet</a> <a class="js-button js-tidy">Do HTML Tidy</a>{/if}

				{elseif $i.type=='typeable'}
					{if $i.multiple}{assign var=selectName value=$k|replace:'[]':'[type][]'}{assign var=inputName value=$k|replace:'[]':'[value][]'}
					{else}			{assign var=selectName value=$k|cat:'[type]'}{assign var=inputName value=$k|cat:'[value]'}{/if}

					<select id="form{$fid}_{$kid}_type" name="{$selectName}" class="longtext field-type-{$i.type} select {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" {if @$i.readonly||@$options.mode.readonly}disabled=""{/if}>
					{if isset($i.null) && $i.null}<option value="0" title="&mdash;">&mdash;</option>{/if}
					{foreach from=$i.types item=ti key=tk}
						<option {if isset($i_value) && $i_value.type==$ti.id}selected="selected"{/if} value="{$ti.id}" title="{$ti.title|default:''|escape}">{$ti.title|default:''}</option>
					{/foreach}
					</select>

					<input id="form{$fid}_{$kid}_value" name="{$inputName}" type="text" class="{if isset($i.mask)}iMask{/if} field-type-{$i.type} {if @$i.required}required{/if} {if isset($i.fixedLength)}fixedLength:{$i.fixedLength}{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i_value.value|default:''|escape}" {if isset($i.mask)}alt="{ldelim}'type':'fixed','mask':'{$i.mask|escape}','stripMask':true{rdelim}"{/if} autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />

				{elseif $i.type=='list'}
					<select id="form{$fid}_{$kid}" name="{$k}" class="longtext field-type-{$i.type} select {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" {if @$i.readonly||@$options.mode.readonly}disabled=""{/if}>
					{if isset($i.null) && $i.null}<option value="0" title="&mdash;">&mdash;</option>{/if}
					{foreach from=$i.values item=vi key=vk}
						<option {if isset($i_value) && $i_value==$vi.id}selected="selected"{/if} value="{$vi.id}" title="{$vi.title|default:''|escape}">{$vi.title|default:''}</option>
					{/foreach}
					</select>

				{elseif $i.type=='radio'}
					<div class="radio-group">
					{if isset($i.null) && $i.null}
						<label>
							<input type="radio" id="form{$fid}_{$kid}_null" name="{$kid}" value="" class="field-type-{$i.type} {if @$i.required}required{/if}" title="&mdash;" {if !isset($i_value)||$i_value===''}checked="checked"{elseif @$i.readonly||@$options.mode.readonly}disabled=""{/if} />
							&mdash;
						</label>
					{/if}
					{foreach from=$i.values item=vi key=vk}
						<label for="form{$fid}_{$kid}_{$vk}">
							<input type="radio" id="form{$fid}_{$kid}_{$vk}" name="{$kid}" value="{$vi.id}" {if isset($i_value) && $i_value==$vi.id}checked="checked"{elseif @$i.readonly||@$options.mode.readonly}disabled=""{/if} value="{$vi.id}" title="{$vi.title|default:''|escape}" />
							{$vi.title|default:''}
						</label>
					{/foreach}
					</div>

				{elseif $i.type=='check'}
					<input name="{$k}" type="hidden" value="0" />
					<label for="form{$fid}_{$kid}">
						<input id="form{$fid}_{$kid}" name="{$k}" type="checkbox" class="validate-{$i.type} {if @$i.required}required{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="1" {if $i_value>0}checked="checked"{/if} autocomplete="off" />
						{$i.label|default:$k} {if @$i.required}<a class="required" title="required">*</a>{/if}
					</label>

				{elseif $i.type=='file'}
					<input id="form{$fid}_{$kid}" name="{$k}" type="file" class="validate-{$i.type} {if @$i.required}required{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="" />
					{if $i_value}
						{if (strpos( 'jpg,jpeg,png,gif', trim(substr($i_value,-4,4),' .') )!==false)}
							<img src="{$i_value}" style="float:right;border:1px solid #777;padding:5px;margin:5px;" alt="{$i_value|escape}" title="{$i_value|escape}" />
						{else}
							<a href="{$i_value}" target="_blank">download [{$i_value}, {$i_value}]</a>
						{/if}
					{/if}

				{elseif $i.type=='captcha'}
					{if @$i.readonly||@$options.mode.readonly}—{else}{php}echo recaptcha::getHtml();{/php}{/if}

				{elseif $i.type=='money'}
					<input id="form{$fid}_{$kid}" name="{$k}" type="text" class="iMask textbox validate-{$i.type} field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i_value|default:''|escape}" alt="{ldelim}'type':'number','groupSymbol':',','groupDigits':3,'decSymbol':'.','decDigits':2,'stripMask':false{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />

				{elseif $i.type=='date' || $i.type=='time'}
					<input id="form{$fid}_{$kid}" name="{$k}" type="text" class="iMask textbox validate-{$i.type} field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''} dateFormat:{if $i.type=='date'}'%d.%m.%Y' datepicker{else}'%H:%M' timepicker{/if}" value="{$i_value|default:''|escape}" alt="{ldelim}'type':'fixed','mask':{if $i.type=='date'}'99.99.9999'{else}'99:99'{/if},'stripMask':false{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />

				{elseif $i.type=='month'}
					<input id="form{$fid}_{$kid}" name="{$k}" type="text" class="iMask textbox validate-{$i.type} field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''} dateFormat:'%m.%Y'" value="{$i_value|default:''|escape}" alt="{ldelim}'type':'fixed','mask':'99.9999','stripMask':false{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />

				{elseif $i.type=='email'}
					<input id="form{$fid}_{$kid}" name="{$k}" type="text" class="textbox longtext validate-{$i.type} field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i_value|default:''|escape}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />

				{elseif $i.type=='phone'}
					<input id="form{$fid}_{$kid}" name="{$k}" type="text" class="textbox longtext iMask validate-{$i.type} field-type-{$i.type} {if @$i.required}required{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i_value|trim:'+'|default:''|escape}" alt="{ldelim}'type':'fixed','mask':'+9 999 999-9999','stripMask':true{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />

				{else}
					{capture assign=type}text{/capture} {*{if $i.type=='string'}text{else}{$i.type}{/if}{/capture}*}
					<input id="form{$fid}_{$kid}" name="{$k}" type="{$type}" class="textbox longtext {if isset($i.mask)}iMask{/if} field-type-{$i.type} {if @$i.required}required{/if} {if isset($i.fixedLength)}fixedLength:{$i.fixedLength}{/if} {if @$i.oneof}one-of oneOf:'{$i.oneof}'{/if} msgPos:'form{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i_value|default:''|escape}" {if isset($i.mask)}alt="{ldelim}'type':'fixed','mask':'{$i.mask|escape}','stripMask':true{rdelim}"{/if} autocomplete="{if @$i.autocomplete}on{else}off{/if}" {if @$i.readonly||@$options.mode.readonly}readonly=""{/if} />
				{/if}

{/foreach}

			{if $i.multiple}
				{capture assign=js_rel}{if $i.type=='typeable'}form{$fid}_{$kid}_container{else}form{$fid}_{$kid}{/if}{/capture}
				<a class="js-button js-button-multiplicate" rel="{$js_rel}">{'add'|translate}</a>
				<a class="js-button js-button-clean" rel="{$js_rel}">{'remove empty'|translate}</a>
			{/if}

			{if (!$options.mode.readonly && !$i.readonly) && $i.info}
				<label id="form{$fid}_{$kid}_info" for="form{$fid}_{$kid}" class="message">{$i.info|default:'<!-- -->'}</label>
			{/if}

		</div>

		{/if}
	{/if}
{/foreach}

{if !$options.mode.readonly && !$options.mode.nosubmit}
	<br class="clear" />
	<div class="form-field clearfix"><label>&nbsp;</label>
		<input type="submit" value="{$options.submit|default:'Сохранить'|translate}" class="btn-submit button" />
		{if $options.buttons}
		{foreach from=$options.buttons item=button}
			<input type="submit" value="{$button.title|escape}" title="{$button.title|escape}" class="btn-submit button {$button.class}" {if $button.name}name="{$button.name|escape}"{/if} />
		{/foreach}
		{/if}
	</div>
{/if}

	{$hiddenfields}
</form>
{/strip}{/if}

{$options|@d}